package com.aneliya.validator;

import java.util.EventObject;

import javax.swing.event.EventListenerList;

import sun.reflect.generics.reflectiveObjects.NotImplementedException;

public abstract class Validator implements IValidator {
	
	public Boolean isValid() {
		throw new NotImplementedException();
	}
	
	public Boolean isActive() {
		return true;
	}
	
	protected EventListenerList listeners;
	
	public Validator() {
		listeners = new EventListenerList();
	}
	
	public void addValidatorListener(ValidatorListener listener) {
		listeners.add(ValidatorListener.class, listener);
	}
	
	public void removeValidatorListener(ValidatorListener listener) {
		listeners.remove(ValidatorListener.class, listener);
	}
	
	protected void dispatchValidatorChanged() {
		ValidatorListener[] list = listeners.getListeners(ValidatorListener.class);
	    for (ValidatorListener listener : list) {
	    	EventObject event = new EventObject(this);
			listener.validatorChanged(event);
		}
	}
}
